<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org">
<script type="text/javascript" th:src="@{/ckeditor/ckeditor.js}"></script>

<head th:include="header::header" />
<body>
	<div id="dgtoolbar" class="datagrid-toolbar">
		<a id="newbtn" href="#" class="easyui-linkbutton" iconCls="icon-add" plain="true" title="新增">新增</a>
		<a id="deletebtn" href="#" class="easyui-linkbutton" iconCls="icon-remove" plain="true" title="批量删除">删除</a>
		<a id="reloadbtn" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true">刷新</a>
		<a id="shenhe" href="#" class="easyui-linkbutton" iconCls="icon-reload" plain="true" onclick="shenhe()">审核</a>
	</div>
	<!-- 表格 -->
	<table id="dg" class="easyui-datagrid" data-options="url:'pageQuery',idField:'iid',rownumbers:true,singleSelect:false,method:'post',toolbar:'#dgtoolbar',pagination:true,pageSize:20,pageList:[20,30,50],fit:true,onLoadSuccess:onDGLoadSuccess">
		<thead>
			<tr>
				<th data-options="field:'iid'" checkbox="true"></th>
				<th data-options="field:'ctitle'" width="150" align="center">标题</th>
				<th data-options="field:'cdesc'" width="150" align="center">摘要</th>
				<th data-options="field:'articletypeiid',formatter:Data.articletypeFormatter" width="150" align="center">分类</th>
				<!--<th data-options="field:'ccontent',formatter:formatCellTooltip" width="150" align="center">内容</th>-->
				<th data-options="field:'ispassed',formatter:Data.issueFormat"  width="100" align="center">是否审核</th>
				<th data-options="field:'isort'" width="80" align="center">排序</th>
				<th data-options="field:'ccreator'" width="80" align="center">添加人</th>
				<th data-options="field:'dcreator'" width="150" align="center">添加时间</th>
				<th data-options="field:'opt',formatter:onItemOptEdit" width="40" align="center">修改</th>
				<th data-options="field:'opt1',formatter:onItemOptDelete" width="40" align="center">删除</th>
				<th data-options="field:'opt2',formatter:onItemOptShow" width="40" align="center">查看</th>
			</tr>
		</thead>
	</table>
	<!-- 弹出框 -->
	<div id="dlg" class="easyui-dialog" title="操作" style="padding:5px;width: 1200px;height: 600px;" data-options="buttons: '#dlg-buttons',closed:'true',modal:true">
		<form id="dataform" method="post" enctype="multipart/form-data">
			<table style="width: 100%">
				<tr>
					<td>标题:</td>
					<td><input name="iid" id="iid" type="hidden">
					<input name="ctitle" class="easyui-textbox" style="width: 200px" data-options="required:true" ></input></td>
					<!--<td  rowspan="6">
				<script type="text/plain" id="myEditor" style="width:1000px;height:240px;">
    				 <p id="xw4">这里我可以写一些内容</p>
				 </script>
							</td>-->
					<td>摘要:</td>
					<td><input name="cdesc" class="easyui-textbox" style="width: 200px" data-options=""></input></td>
				</tr>
				<tr>
					<td>分类:</td>
					<td><input id="articletypeiid" name="articletypeiid" class="easyui-combobox" style="width: 200px" data-options="panelHeight:'auto',required:true,url:'../dicdetails/findItems?ckey=articletype',valueField:'cvalue',textField:'cname'"></input></td>
					<td>封面图片:</td>
					<td><input type="file" name="file" id="file"></input></td>

				</tr>
				<tr>
					<!-- <td>是否审核通过:</td>
					<td><input name="ispassed" id="ispassed" class="easyui-combobox" style="width: 200px" data-options="panelHeight:'auto',required:true,url:'../dicdetails/findItems?ckey=sf',valueField:'cvalue',textField:'cname'"></input></td>-->
					<td>排序:</td>
					<td><input name="isort" class="easyui-numberspinner" style="width: 200px" data-options="min:0,max:100,required:true"></input></td>

				</tr>
				<tr >
					<td colspan="4">
						<textarea name="ccontent" id="editor"></textarea>
						<script type="text/javascript">CKEDITOR.replace('editor');</script>
                    </td>
				</tr>

				<input type="hidden" name="icreator" id="icreator"/>
			</table>

		</form>
	</div>
	<!-- 弹出框工具栏 -->
	<div id="dlg-buttons">
		<a id="dlg-savebtn" href="javascript:void(0)" style="width:50" class="easyui-linkbutton" iconCls="icon-ok">保存</a>
		<a id="dlg-closebtn" href="javascript:void(0)" style="width:50" class="easyui-linkbutton" iconCls="icon-no">关闭</a>
	</div>
	<!-- 弹出框 -->
	<div id="dlg_scene" class="easyui-dialog" title="操作" style="padding:5px"
		 data-options="buttons: '#dlg-buttons_scene',closed:'true',modal:true">
		<form id="dataform_scene" method="post" enctype="multipart/form-data">
			<table>
				<tr>
					<td>是否审核通过:</td>
					<td>
					<td><input name="iid" id="iid1" type="hidden">
						<input name="ispassed" id="ispassed" class="easyui-combobox" style="width: 200px"
							   data-options="panelHeight:'auto',required:true,url:'../dicdetails/findItems?ckey=sf',valueField:'cvalue',textField:'cname'"></input>
					</td>
				</tr>
			</table>
		</form>
	</div>
	<!-- 弹出框工具栏 -->
	<div id="dlg-buttons_scene">
		<a id="dlg-savebtn_scene" onclick="submit_scene()" href="javascript:void(0)" style="width:50"
		   class="easyui-linkbutton" iconCls="icon-ok">保存</a> <a id="dlg-closebtn_scene" href="javascript:void(0)"
																 style="width:50" class="easyui-linkbutton"
																 iconCls="icon-no">关闭</a>
	</div>
</body>
<script type="text/javascript" th:src="@{/common/GridView.js}"></script>
<script type="text/javascript">
	var um = UE.getEditor('myEditor');

</script>

<script type="text/javascript" th:inline="javascript">
	$(document).ready(function() {
		$("#ilocation").combobox({
			onChange : function() {
				$("#clocation").val($("#ilocation").combobox("getText"));

			}
		})

        var iusertype = /*[[${iusertype}]]*/
        if (iusertype == 3) {
            $("#shenhe").hide();
        }

	})
    //格式化单元格提示信息
    function formatCellTooltip(value){
        return "<span title='" + value + "'>" + value + "</span>";
    }
    //新增时置空富文本编辑器内容
    function subNewHandler() {
        CKEDITOR.instances.editor.setData("");
        $("#icreator").val(0);
    }
    //edit时回显富文本编辑器内容
    function subEditHandler(row) {
        CKEDITOR.instances.editor.setData(row.ccontent);
    }
    //查看时回显富文本编辑器内容
    function subShowHandler(row) {
        CKEDITOR.instances.editor.setData(row.ccontent);
    }

    function shenhe() {
        var rows = $("#dg").datagrid("getSelections");
        if (rows == null || rows.length == 0) {
            $.messager.alert("提示", "请选择后，再操作！");
            return;
        }
        if (rows.length != 1) {
            $.messager.alert("提示", "只能选择一条数据进行操作！");
            return;
        }
        $("#dlg-savebtn_scene").linkbutton("enable");
        $("#dataform_scene").form("clear");
        $("#dlg_scene").dialog({
            iconCls: "icon-add",
            title: "审核" + indexname
        });
        $("#dlg_scene").dialog("open");
        $("#dlg_scene").window("center");
        $("#dlg-savebtn_scene").linkbutton({
            "text": "保存"
        });
        $("#dlg-savebtn_scene").show();
        $("#iid1").val(rows[0].iid);

    }

    function submit_scene() {
        $("#dlg-savebtn_scene").linkbutton("disable");
        try {
            if (subSubmitHandler && typeof (subSubmitHandler) == "function") {
                subSubmitHandler();
            }
        } catch (e) {

        }
        //Common.showProgress("正在请求中...");
        $("#dataform_scene").form("submit", {
            url: "shenhe",
            onSubmit: function () {
                var bool = $("#dataform_scene").form("validate");
                if (bool == false) {
                    $("#dlg-savebtn_scene").linkbutton("enable");
                    Common.closeProgress();
                }
                return bool;
            },
            error: function (XMLHttpRequest, textStatus, errorThrow) {
                $("#dlg-savebtn_scene").linkbutton("enable");
                Common.showAlert("请求错误", XMLHttpRequest.responseText, "error");
                Common.closeProgress();
            },
            success: function (data, textStatus) {
                Common.closeProgress();
                $("#dlg-savebtn_scene").linkbutton("enable");
                var answerJson = eval('(' + data + ')');
                Common.showAlert("提示", answerJson.msg, "info");
                if (answerJson.success) {
                    $("#dataform_scene").form("clear");
                    $("#dlg_scene").dialog("close");
                    onClearSelected();
                    $("#dg").datagrid("reload");
                }

            }
        });
    }
</script>
</html>